package cn.anxingongyou.anxin.service.impl;

import cn.anxingongyou.anxin.entity.Admin;
import cn.anxingongyou.anxin.mapper.AdminMapper;
import cn.anxingongyou.anxin.service.AdminService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AdminServiceImpl implements AdminService {

    private final AdminMapper adminMapper;

    @Autowired
    public AdminServiceImpl(AdminMapper adminMapper) {
        this.adminMapper = adminMapper;
    }

    @Override
    public int insert(Admin admin) {
        return adminMapper.insertSelective(admin);
    }

    @Override
    public int deleteByPrimaryKey(Long id) {
        return adminMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Admin admin) {
        return adminMapper.updateByPrimaryKeySelective(admin);
    }

    @Override
    public Admin selectOne(Admin admin) {
        return adminMapper.selectOne(admin);
    }

    @Override
    public Admin selectOneByPrimaryKey(Long id) {
        return adminMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<Admin> page(int pageNum, int pageSize, Admin admin) {
        String orderBy = "id desc";
        PageHelper pageHelper = new PageHelper();
        pageHelper.startPage(pageNum,pageSize,orderBy);
        List<Admin> list = adminMapper.select(admin);
        PageInfo<Admin> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

}
